package logic

import (
	"context"
	"time"
	"zhongxc.cc/grpc-common/admin-user/client/user"

	"zhongxc.cc/admin-user-api/internal/svc"
	"zhongxc.cc/admin-user-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUserLogicLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLogic {
	return &UserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UserLogic) Info(ctx context.Context, req *types.InfoRequest) (resp *user.UserInfoRes, err error) {
	// todo: add your logic here and delete this line
	ctx, cancelFunc := context.WithTimeout(ctx, 5*time.Second)
	defer cancelFunc()

	// 从登录信息中获取用户ID
	userInfo := l.svcCtx.GetUserInfo(ctx)
	inReq := &user.UserInfoReq{}
	inReq.UserId = userInfo.UserId

	info, err := l.svcCtx.UserRpc.Info(ctx, inReq)
	if err != nil {
		logx.Error(err)
		return nil, err
	}
	return info, nil
}
